/**
 * Ajax进行用户名重名查找
 */
package controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Query;

import hibernate.Adminstab;
import hibernate.AdminstabDAO;
import hibernate.HibernateSessionFactory;

public class SignUpAction extends HttpServlet {
	public void init (ServletConfig config) throws ServletException {
		
	}
	protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException {
		request.setCharacterEncoding("UTF-8");
		String account = request.getParameter("account");
		
		//HibernateSessionFactory.getSession().beginTransaction();
		AdminstabDAO adminstabDAO = new AdminstabDAO();
		
		boolean re = adminstabDAO.accountCheck(account);
		//boolean re = true;
		
		//adminstabDAO.getSession().getTransaction().commit();
		//adminstabDAO.getSession().close();
		
		
		response.setContentType("text/xml; charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		out.println("<response>");
		out.println("<res>"+re+"</res>");
		out.println("</response>");
		out.close();
	}
	
//public Adminstab loginCheck(String name,String password){
//		
//		
//		try {
//			String hqlString = "from Adminstab as a where a.account=:p_account and a.pwd = :p_pwd";
//			Query queryObject = getSession().createQuery(hqlString);
//			queryObject.setString("p_account", name);
//			queryObject.setString("p_pwd", password);
//			List<Adminstab> list = queryObject.list();
//			if(list !=null && list.size() > 0){                //��¼�ɹ�
//				return list.get(0);
//			}else {
//				return null;
//			}
//		} catch (RuntimeException re) {                       //��¼ʧ��
//			
//			throw re;
//		}
//	}
//	
//	public boolean accountCheck(String name){
//		
//		try {
//			String hqlString = "from Adminstab as a where a.account=:p_account";
//			Query queryObject = getSession().createQuery(hqlString);
//			queryObject.setString("p_account", name);
//			List<Adminstab> list = queryObject.list();
//			if(list !=null && list.size() > 0){                //������
//				return false;
//			}else {
//				return true;                                  //������
//			}
//		} catch (RuntimeException re) {                       
//			
//			throw re;
//		}
//	}
}
